Linux开发

推荐列表 站点导航

当前位置:首页 > 服务器技术 > Linux开发 >

初识Python:Hello World和字符串操作

来源:网络整理  作者:  发布时间:2020-12-22 22:08
开始之前,说一下本文中的 代码 和 视频 可以在我的 GitHub 上找到。 那么,让我们开始吧!如果你糊涂了,我建议你...

那么,让我们开始吧!如果你糊涂了,我建议你在单独的选项卡中打开下面的视频。

Python 的 Hello World 和字符串操作视频

 

开始 (先决条件)

首先在你的操作系统上安装 Anaconda (Python)。你可以从官方网站下载 anaconda 并自行安装,或者你可以按照以下这些 anaconda 安装教程进行安装。

在 Windows 上安装 Anaconda: 链接

在 Mac 上安装 Anaconda: 链接

在 Ubuntu (Linux) 上安装 Anaconda:链接

 

打开一个 Jupyter Notebook

打开你的终端(Mac)或命令行,并输入以下内容(请参考视频中的 1:16 处)来打开 Jupyter Notebook:

jupyter notebook

 

打印语句/Hello World

在 Jupyter 的单元格中输入以下内容并按下 shift + 回车来执行代码。

# This is a one line comment

print('Hello World!')

 

字符串和字符串操作

字符串是 Python 类的一种特殊类型。作为对象,在类中,你可以使用 .methodName() 来调用字符串对象的方法。字符串类在 Python 中默认是可用的,所以你不需要 import 语句来使用字符串对象接口。

# Create a variable

# Variables are used to store information to be referenced

# and manipulated in a computer program.

firstVariable = 'Hello World'

print(firstVariable)

# Explore what various string methods

print(firstVariable.lower())

print(firstVariable.upper())

print(firstVariable.title())

初识Python:Hello World和字符串操作

# Use the split method to convert your string into a list

print(firstVariable.split(' '))

# You can add strings together.

a = "Fizz" + "Buzz"

print(a)

 

查询方法的功能

对于新程序员,他们经常问你如何知道每种方法的功能。Python 提供了两种方法来实现。

1、(在不在 Jupyter Notebook 中都可用)使用 help 查询每个方法的功能。

初识Python:Hello World和字符串操作

2.(Jupyter Notebook 专用)你也可以通过在方法之后添加问号来查找方法的功能。

# To look up what each method does in jupyter (doesnt work outside of jupyter)

firstVariable.lower?

初识Python:Hello World和字符串操作

 

结束语

如果你对本文或在 YouTube 视频的评论部分有任何疑问,请告诉我们。文章中的代码也可以在我的 GitHub 上找到。本系列教程的第 2 部分是简单的数学操作

 

64位Ubuntu14.04系统下加载内核模块hello world:

在CentOS 7上安装.NET Core R2跑Hello World:

Ubuntu16.04安装Docker1.12+开发实例+hello world+web应用容器:

Node.js入门基础知识:Hello world!:

制作Ubuntu的deb格式包 从Hello World做起:

相关热词:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供用于网络技术学习参考,学习中请遵循相关法律法规!

本文地址: https://v30.fanwenzhu.com/server/kaifa/7507.shtml

相关文章
Copyright © www.juheyunku.com      关于 | 合作 | 声明 | 联系 | 更新 | 地图 | Tags

初识Python:Hello World和字符串操作

2020-12-22 编辑:

那么,让我们开始吧!如果你糊涂了,我建议你在单独的选项卡中打开下面的视频。

Python 的 Hello World 和字符串操作视频

 

开始 (先决条件)

首先在你的操作系统上安装 Anaconda (Python)。你可以从官方网站下载 anaconda 并自行安装,或者你可以按照以下这些 anaconda 安装教程进行安装。

在 Windows 上安装 Anaconda: 链接

在 Mac 上安装 Anaconda: 链接

在 Ubuntu (Linux) 上安装 Anaconda:链接

 

打开一个 Jupyter Notebook

打开你的终端(Mac)或命令行,并输入以下内容(请参考视频中的 1:16 处)来打开 Jupyter Notebook:

jupyter notebook

 

打印语句/Hello World

在 Jupyter 的单元格中输入以下内容并按下 shift + 回车来执行代码。

# This is a one line comment

print('Hello World!')

 

字符串和字符串操作

字符串是 Python 类的一种特殊类型。作为对象,在类中,你可以使用 .methodName() 来调用字符串对象的方法。字符串类在 Python 中默认是可用的,所以你不需要 import 语句来使用字符串对象接口。

# Create a variable

# Variables are used to store information to be referenced

# and manipulated in a computer program.

firstVariable = 'Hello World'

print(firstVariable)

# Explore what various string methods

print(firstVariable.lower())

print(firstVariable.upper())

print(firstVariable.title())

初识Python:Hello World和字符串操作

# Use the split method to convert your string into a list

print(firstVariable.split(' '))

# You can add strings together.

a = "Fizz" + "Buzz"

print(a)

 

查询方法的功能

对于新程序员,他们经常问你如何知道每种方法的功能。Python 提供了两种方法来实现。

1、(在不在 Jupyter Notebook 中都可用)使用 help 查询每个方法的功能。

初识Python:Hello World和字符串操作

2.(Jupyter Notebook 专用)你也可以通过在方法之后添加问号来查找方法的功能。

# To look up what each method does in jupyter (doesnt work outside of jupyter)

firstVariable.lower?

初识Python:Hello World和字符串操作

 

结束语

如果你对本文或在 YouTube 视频的评论部分有任何疑问,请告诉我们。文章中的代码也可以在我的 GitHub 上找到。本系列教程的第 2 部分是简单的数学操作

 

64位Ubuntu14.04系统下加载内核模块hello world:

在CentOS 7上安装.NET Core R2跑Hello World:

Ubuntu16.04安装Docker1.12+开发实例+hello world+web应用容器:

Node.js入门基础知识:Hello world!:

制作Ubuntu的deb格式包 从Hello World做起:

本站内容来源于网络,如有侵权请与我们联系,我们会及时删除,我们深感抱歉!
注:本站所有信息仅供学习参考!
本文地址为 https://v30.fanwenzhu.com/server/kaifa/7507.shtml

相关文章

风云图片

推荐阅读

返回Linux开发频道首页